package com.hspedu.hspspringmvc.xml;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.InputStream;

/**
 * packageName com.hspedu.hspspringmvc.xml
 *
 * @author 你的名字
 * @version JDK 8
 * @className XMLPaser (此处以class为例)
 * @date 2025/2/11
 * @description TODO
 */
public class XMLPaser {
    public static String getbasePackage(String xmlPath)  {


        try{
            SAXReader saxReader = new SAXReader();
            InputStream resourceAsStream =
                    XMLPaser.class.getClassLoader().getResourceAsStream(xmlPath);
            Document document = saxReader.read(resourceAsStream);
            Element rootElement = document.getRootElement();
            Element componentScanElement =
                    rootElement.element("component-scan");
            Attribute attribute =
                    componentScanElement.attribute("base-package");
            String basePackage = attribute.getText();
            return basePackage;

        }catch (DocumentException e){
            e.printStackTrace();
        }

        return "";
    }
}
